<%--
  Created by IntelliJ IDEA.
  User: 12459
  Date: 2024/11/4
  Time: 16:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <meta charset="UTF-8">
</head>

<body>
  <form>
    <c:choose>
      <c:when test="${requestScope.user.id!=null}">
        <input type="hidden" value="modify" name="method">
         用户ID:<input type="text" value="${requestScope.user.id}" name="id" readonly><br>
      </c:when>
      <c:otherwise>
        <input type="hidden" value="save" name="method">
      </c:otherwise>
    </c:choose>
    用户名:<input type="text" value="${requestScope.user.userName}" name="userName"><br>
    用户编码:<input type="text" value="${requestScope.user.userCode}" name="userCode"><br>
    用户密码:<input type="text" value="${requestScope.user.userPassword}" name="userPassword"><br>
    性别:<input type="radio" name="gender" <c:if test="${requestScope.user.gender==1}">checked</c:if> value="1">男
    <input type="radio" name="gender" <c:if test="${requestScope.user.gender==2}">checked</c:if> value="2">女<br>
    生日:<input type="date" value="${requestScope.user.birthday}" name="birthday"><br>
    用户地址:<input type="text" value="${requestScope.user.address}"  name="address"><br>
    <input type="button" value="提交">
  </form>
</body>
<script src="/js/jquery-3.7.1.min.js"></script>
<script type="text/javascript">
  $(function () {
    $("input[type='button']").click(function () {
      var formData = $("form").serialize();
      $.ajax({
        url:"/user/"+$("input[type='hidden']").val(),
        data:formData,
        type:"post",
        dataType:"json",
        success:function (data) {
          alert(data.message)
          console.log(data.message)
          if(data.code === 200){
            location.href = "/user/findByPage"
          }
        }
      })
    })
  })

</script>
</html>
